package com.goktech.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Boolean state;
    private String errorMsg;
    private T data;
    private Long total;
    private String code;

    public static <T> Result<T> ok() {
        return new Result<>(true, null, null, null, null);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(true, null, data, null, null);
    }

    public static Result<List<?>> ok(List<?> data, Long total) {
        return new Result<>(true, null, data, total, null);
    }

    public static <T> Result<T> fail(String errorMsg) {
        return new Result<>(false, errorMsg, null, null, null);
    }

    public static <T> Result<T> fail(String errorMsg, String code) {
        return new Result<>(false, errorMsg, null, null, code);
    }
}
